﻿using Dynamic.Api.TestService.Model;
using Microsoft.AspNetCore.Mvc;

namespace Dynamic.Api.TestService
{

    /// <summary>
    /// 
    /// </summary>
    public class EmployeeService : IEmployeeService
    {

        private static List<Employee> employees = new List<Employee>();
        /// <summary>
        /// 
        /// </summary>
        public EmployeeService()
        {
            employees.Add(new Employee("1001", "苦逼策划"));
            employees.Add(new Employee("1002", "加班狗程序员"));
        }

        /// <summary>
        /// 用户列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<Employee>> GetAll()
        {
            return await Task.FromResult(employees);
        }


        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public async Task<bool> AddUserAsync(string userId, string userName)
        {
            employees.Add(new Employee(userId, userName));
            return await Task.FromResult(true);
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<bool> DeleteUserAsync([FromBody] IdParam param)
        {
            var user = employees.Where(it => it.Id == param.userId)?.FirstOrDefault();
            if (user != null)
            {
                employees.Remove(user);
                return await Task.FromResult(true);
            }
            return await Task.FromResult(false);
        }


    }
}
